/*
 * @Author: SiMeiyu 
 * @Date: 2017-08-30 09:58:01 
 */ 
var geoCoordMap = {
  '延寿': [128.331644, 45.451897],
  '临江': [126.918087, 41.811979],
  '嘉兴': [120.755486, 30.746129],
  '四平': [124.350398, 43.16642],
  '营口': [122.235418, 40.667012],
  '密云': [116.801346, 40.35874],
  '威海': [122.12042, 37.513068],
  '杭州': [120.15507, 30.274085],
  '集安': [126.194031, 41.125307],
  '贵阳': [106.630154, 26.647661],
  '抚顺': [123.957208, 41.880872],
  '海门': [121.181615, 31.871173],
  '珠海': [113.576726, 22.270715],
  '河北': [114.475704, 38.584854],
  '深圳': [114.057868, 22.543099],
  '黄浦': [121.484443, 31.231763],
  '蓬莱': [120.758848, 37.810661],
  '吉林': [126.549572, 43.837883],
  '甘肃': [103.826308, 36.059421],
  '龙井': [129.427066, 42.766311],
  '茂名': [110.925456, 21.662999],
  '丹东': [124.354707, 40.0005],
  '晋中': [112.752695, 37.687024],
  '浙江': [120.152792, 30.267447],
  '海城': [122.685217, 40.882377],
  '溆浦': [110.594921, 27.908281],
  '北京': [116.407526, 39.90403],
  '铁岭': [123.726166, 42.223769],
  '大同': [113.61244, 40.040295],
  '金坛': [119.597897, 31.723247],
  '齐齐哈尔': [126.661669, 45.742347],
  "咸阳": [108.708991, 34.329605],
  "四川": [104.075931, 30.651652],
  "福田": [114.055036, 22.52153],
  "盘锦": [122.070714, 41.119997],
  "中山": [113.392782, 22.517646],
  "福建": [119.295144, 26.10078],
  "泰顺": [119.717649, 27.556884],
  "宝山": [131.401589, 46.577167],
  "庆安": [127.507825, 46.880102],
  "海淀": [116.298056, 39.959912],
  "大兴": [116.341395, 39.726929],
  "桦川": [130.719081, 47.023001],
  "惠州": [114.416196, 23.111847],
  "青岛": [120.38264, 36.067082],
  "朝阳": [116.443108, 39.92147],
  "沈阳": [123.431475, 41.805698],
  "菏泽": [115.480656, 35.23375],
  "南通": [120.894291, 31.980172],
  "南充": [106.110698, 30.837793],
  "双城": [126.312745, 45.383263],
  "南京": [118.796877, 32.060255],
  "新疆": [87.627704, 43.793026],
  "成都": [104.066541, 30.572269],
  "陕西": [108.954239, 34.265472],
  "黄岛": [120.04619, 35.872664],
  "温州": [120.699367, 27.994267],
  '石家庄': [114.51486, 38.042307],
  "延寿": [128.331644, 45.451897],
  "邢台": [114.504844, 37.070589],
  "赣州": [114.93503, 25.831829],
  "义乌": [120.075058, 29.306841],
  "南昌": [115.858198, 28.682892],
  "闵行": [121.381709, 31.112813],
  "长宁": [121.424624, 31.220367],
  "道里": [126.616957, 45.755777],
  "乳山": [121.539765, 36.919816],
  "双流": [103.923648, 30.574473],
  "广州": [113.264435, 23.129163],
  "西城": [116.365868, 39.912289],
  "佳木斯": [130.318917, 46.799923],
  "皇姑": [123.44197, 41.824796],
  "榆树": [126.533146, 44.840288],
  "临汾": [111.518976, 36.088005],
  "上海": [121.473701, 31.230416],
  "内蒙古": [111.765618, 40.817498],
  "尚志": [128.009895, 45.209586],
  "湖里": [118.146769, 24.512905],
  "台州": [121.420757, 28.656386],
  "潍坊": [119.161756, 36.706774],
  "苏州": [120.585316, 31.298886],
  "房山": [116.143267, 39.749144],
  "即墨": [120.447128, 36.389639,],
  "舒兰": [126.965607, 44.406106],
  "延吉": [129.508946, 42.891255],
  "三河": [117.078295, 39.982718],
  "大连": [121.614682, 38.914003],
  "辉南": [126.046912, 42.684993],
  "无锡": [120.31191, 31.49117],
  "常州": [119.973987, 31.810689],
  "广西": [108.327546, 22.815478],
  "泉州": [118.675676, 24.874132],
  "昌平": [116.231204, 40.22066],
  "海阳": [121.158434, 36.776378],
  "郑州": [113.625368, 34.7466],
  "东城": [116.416357, 39.928353],
  "黄骅": [117.330048, 38.371383],
  "武侯": [104.04339, 30.641982],
  "鸡东": [131.12408, 45.260412],
  "龙口": [120.477813, 37.646108],
  "汤原": [129.905072, 46.730706],
  "湖北": [114.341862, 30.546498],
  "克拉玛依": [84.889207, 45.579889],
  "厦门": [118.089425, 24.479834],
  "哈尔滨": [126.534967, 45.803775],
  "秦皇岛": [119.600493, 39.935385],
  "江苏": [118.763232, 32.061707],
  "常熟": [120.752481, 31.654376],
  "烟台": [121.447935, 37.463822],
  "和平": [117.21451, 39.116949],
  "环翠": [122.123444, 37.501991],
  "宣武门外东大街": [116.378888, 39.899332],
  "张家港": [120.553284, 31.870367],
  "临安": [119.724733, 30.233873],
  "延安": [109.489727, 36.585455],
  "天津": [117.200983, 39.084158],
  "城阳": [120.39631, 36.307064],
  "石景山": [116.222982, 39.906611],
  "长沙": [112.938814, 28.228209],
  "安徽": [117.284923, 31.861184],
  "昆山": [120.980737, 31.385598],
  "徐汇": [121.436525, 31.188523],
  "东港": [124.152705, 39.863008],
  "廊坊": [116.683752, 39.538047],
  "鞍山": [122.994329, 41.108647],
  "海陵": [119.919425, 32.491016],
  "黑龙江": [126.661669, 45.742347],
  "西藏": [91.117212, 29.646923],
  "河南": [113.274379, 34.445122],
  "湖南": [112.98381, 28.112444],
  "佛山": [113.121416, 23.021548],
  "珲春": [130.366036, 42.862821],
  "扬州": [119.412966, 32.39421],
  "日照": [119.526888, 35.416377],
  "唐山": [118.180194, 39.630867],
  "同江": [132.510919, 47.642707],
  "荣成": [122.486658, 37.16516],
  "虎林": [132.93721, 45.762686],
  "武汉": [114.305393, 30.593099],
  "合肥": [117.227239, 31.820587],
  "荆州": [112.239741, 30.335165],
  "丰台": [116.287149, 39.858427],
  "山东": [117.020359, 36.66853],
  "舟山": [122.207216, 29.985295],
  "连云港": [119.221611, 34.596653],
  "西安": [108.940175, 34.341568],
  "济南": [117.12, 36.651216],
  "绵阳": [104.679114, 31.46745],
  "辽宁": [123.42944, 41.835441, ],
  "山西": [112.562398, 37.873532],
  "呼和浩特": [111.749181, 40.842585],
  "河西": [117.223372, 39.109563],
  "兴和": [113.834173, 40.872301],
  "重庆": [106.551557, 29.56301],
  "胶州": [120.033382, 36.26468],
  "宁波": [121.550357, 29.874557],
  "滨海": [119.820831, 33.990334],
  "太原": [112.548879, 37.87059],
  "鸡西": [130.969333, 45.295075],
  "兰山": [118.347707, 35.051729],
  "阳泉": [113.580519, 37.856972],
  "勃利": [130.592171, 45.755063],
  "长春": [125.323544, 43.81707],
  "台湾": [121.495144, 25.00078]
};

var data = [
  {
      name: '乌鲁木齐',
      value: 1005
  }, 
  {
      name: '呼和浩特',
      value: 95
  }, {
      name: '长春',
      value: 260
  }, {
      name: '青岛',
      value: 580
  }, {
      name: '拉萨',
      value: 1600
  }, {
      name: '西宁',
      value: 950
  }, {
      name: '常州',
      value: 1020
  }, {
      name: '重庆',
      value: 1600
  }, {
      name: '昆明',
      value: 342
  }, {
      name: '贵阳',
      value: 20
  }, {
      name: '长沙',
      value: 3400
  }, {
      name: '福州',
      value: 260
  }, {
      name: '深圳',
      value: 580
  }, {
      name: '成都',
      value: 1600
  }
];

var convertData = function(geoCoordMap, data, targ) {
  var res = [];
  for (var i = 0; i < data.length; i++) {
      var dataItem = data[i];
      var fromCoord = geoCoordMap[dataItem.name];
      var toCoord = geoCoordMap[targ];
      if (fromCoord && toCoord) {
          res.push({
              fromName: dataItem.name,
              toName: targ,
              coords: [fromCoord, toCoord]
          });
      }
  }
  return res;
};

var level_t = [], level_m = [], level_b = [];
data.forEach(function(item, index, array) {
  var visitCapacity = item.value;
  switch (true) {
      case visitCapacity >= 1000 && visitCapacity < 10000:
          level_t.push(item);
          break;
      case visitCapacity >= 100 && visitCapacity < 1000:
          level_m.push(item);
          break;
      case visitCapacity >= 1 && visitCapacity < 100:
          level_b.push(item);
  }
});

var cityData = function(geoData, data, srcNam) {
  var tGeoDt = [];
  for (var i = 0, len = data.length; i < len; i++) {
      var tNam = data[i].name
      if (srcNam != tNam) {
          tGeoDt.push({
              name: tNam,
              value: geoData[tNam]
          });
      }

  }
  tGeoDt.push({
      name: srcNam,
      value: geoData[srcNam],
      symbolSize: 10,
      itemStyle: {
          normal: {
              color: '#46bee9'
          }
      },           
      label: {
          normal: {
              show: true,
              formatter: '中国声谷',
              position: 'bottom',
              textStyle: {
                  color: '#cd8e00',
                  fontSize: 14
              }
          }
      }
  },{
      name: srcNam,
      value: geoData[srcNam],
      symbolSize: 40,
      itemStyle: {
          normal: {
              color: '#46bee9',
              opacity:0
          }
      },
  },{
      name: srcNam,
      value: geoData[srcNam],
      symbolSize: 100,
      itemStyle: {
          normal: {
              color: '#46bee9',
              opacity:0
          }
      },
  });
  return tGeoDt;
};
var option_effectScatter = {
  geo: [{
      map: 'world',
      top: 0,
      right: 0,
      left: 0,
      bottom: 0,
      // center: [115.97, 29.71],
      boundingCoords: [
        // 定位左上角经纬度
        [56,55],
        // 定位右下角经纬度
        [166,6]
      ],
      label: {
          emphasis: {
              show: false
          }
      },
      roam: false,
      aspectScale: 0.5,
      itemStyle: {
          normal: {
              areaColor: '#153147',
              borderColor: 'transparent'
          },
          emphasis: {
            areaColor: '#153147',
              borderColor: '#fff'
          }
      },
      regions: [
        {
          name: 'China',
          itemStyle: {
            normal: {
              areaColor: '#153147',
              borderColor: '#132a40',
              borderWidth: 5
            }
          }
        }
      ]
  }],
  // series: [
  //   {
  //       name: '地点',
  //       type: 'effectScatter',
  //       coordinateSystem: 'geo',
  //       zlevel: 9,
  //       rippleEffect: {
  //           brushType: 'stroke'
  //       },
  //       symbolSize: 2,
  //       showEffectOn: 'render',
  //       itemStyle: {
  //           normal: {
  //               color: '#46bee9'
  //           }
  //       },
  //       data: cityData(geoCoordMap, data, "北京")
  //   }, 
  //   // 线
  //   {
  //       name: '0-100',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 2,
  //       large: true,
  //       lineStyle: {
  //           normal: {
  //               color: '#58B3CC',
  //               width: 1,
  //               opacity: 0.5,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_b, '北京')
  //   },
  //   {
  //       name: '100-1000',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 2,
  //       large: true,
  //       lineStyle: {
  //           normal: {
  //               color: '#15af04',
  //               width: 1,
  //               opacity: 0.5,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_m, '北京')
  //   },
  //   {
  //       name: '1000-10000',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 2,
  //       large: true,
  //       lineStyle: {
  //           normal: {
  //               color: '#cd8e00',
  //               width: 1,
  //               opacity: 0.5,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_t, '北京')
  //   }, 
  //   // 移动点
  //   {
  //       name: '0-100',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 3,
  //       large: true,
  //       effect: {
  //           show: true,
  //           constantSpeed: 30,
  //           symbol: 'pin',
  //           symbolSize: 4,
  //           color: 'rgba(88,179,204,0.6)',
  //           trailLength: 0.3
  //       },
  //       lineStyle: {
  //           normal: {
  //               color: '#58B3CC',
  //               width: 0,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_b, '北京')
  //   },
  //   {
  //       name: '100-1000',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 3,
  //       large: true,
  //       effect: {
  //           show: true,
  //           constantSpeed: 30,
  //           symbol: 'pin',
  //           symbolSize: 4,
  //           color: 'rgba(21, 175, 4, 0.6)',
  //           trailLength: 0.3
  //       },
  //       lineStyle: {
  //           normal: {
  //               color: '#15af04',
  //               width: 0,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_m, '北京')
  //   },
  //   {
  //       name: '1000-10000',
  //       type: 'lines',
  //       coordinateSystem: 'geo',
  //       zlevel: 3,
  //       large: true,
  //       effect: {
  //           show: true,
  //           constantSpeed: 30,
  //           symbol: 'pin',
  //           symbolSize: 4,
  //           color: 'rgba(205,142,0,0.6)',
  //           trailLength: 0.3
  //       },
  //       lineStyle: {
  //           normal: {
  //               color: '#cd8e00',
  //               width: 0,
  //               curveness: 0.1
  //           }
  //       },
  //       data: convertData(geoCoordMap, level_t, '北京')
  //   }
  // ]
}
var map_effectScatter = echarts.init(document.getElementById('map-effectScatter'));
map_effectScatter.setOption(option_effectScatter);